﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Text.RegularExpressions;

namespace HeroParser
{
    class Program
    {
        static void Main(string[] args)
        {
            /*
             * 
             * [Edem]
             * Name="Anti-Mage"
             * Hotkey=A
             * Tip="Summon |cffffcc00A|rnti-Mage"
             * Ubertip="Twin sons to the great Prophet, Terrorblade and Magina were blessed with divine powers: Terrorblade granted with an unnatural affinity with life forces; Magina gifted with energy manipulation. Magina's eventual overexposure to the magics gradually augmented his elemental resistances and bestowed him the unique ability to move faster than light itself. Now, broken by Terrorblade's fall to the dark side, Magina answers the Sentinel's call in a desperate bid to redeem his brother. Every bitter strike turns the Scourge's evil essences upon themselves, culminating in a finale that forces his enemy to awaken to the void within and spontaneously implode. |n|n|c000042ffStrength|r - 21 + 1.9|n|c00ff0303Agility|r - 22 + 2.8|n|c000042ffIntelligence|r - 15 + 1.8|n|nLearns Spell Shield, Mana Break, Blink, and |c00ff8000Mana Void|r.|n|nAttack range of 100 (melee). |nMovement speed of 320."
             * Revivetip="Revive |cffffcc00A|rnti-Mage"
             * Awakentip="Revive |cffffcc00A|rnti-Mage"
             * Propernames=Magina
             * 
             */

            String fileName = String.Empty;

            if (args.Count() > 0)
            {
                fileName = args[0];

                using (FileStream inFile = File.OpenRead(fileName))
                {
                    StreamReader inFileReader = new StreamReader(inFile);

                    FileStream outFile = File.Open("DotaHeroes.cs", FileMode.Create);
                    StreamWriter outFileWriter = new StreamWriter(outFile);
                    outFileWriter.AutoFlush = true;

                    String heroData = inFileReader.ReadToEnd();

                    Regex regex = new Regex(@"\[(\w{4})\]
Name=""(.*)""
Propernames=(.*)");
                    MatchCollection collection = regex.Matches(heroData);

                    foreach (Match match in collection)
                    {
                        String heroId = match.Groups[1].Value;
                        String heroName = match.Groups[2].Value;

                        outFileWriter.WriteLine(
                            String.Format(
                                 "heroCodes.Add(\"{0}\", \"{1}\");",
                                 heroId,
                                 heroName
                            ));
                    }
                }
            }
        }
    }
}
